﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using WorkFlowSystem.DataBase;
using System.Drawing;
using System.Data.SqlClient;
using System.Windows.Forms;
using WorkFlowSystem.Common;

namespace WorkFlowSystem
{
    public partial class StandardUi : Form
    {
        public StandardUi()
        {
            InitializeComponent();
            m_modify_mode = false;
        }

        /// <summary>
        /// 设置初始化模式
        /// </summary>
        /// <param name="modify_mode"></param>
        /// <param name="standard_id"></param>
        public void SetMode(bool modify_mode, int standard_id)
        {
            m_modify_mode = modify_mode;
            if (m_std_info == null)
            {
                m_std_info = new StandardInfo();
                m_std_info.std_id = standard_id;
            }
        }

        private int load_standard()
        {
            DBOperator db_op = new DBOperator();
            if (db_op.ConnectDB() < 0)
            {
                MessageBox.Show("无法连接服务器，请检查网络连接");
                return -1;
            }
            string sql = "select * from standard where sid = @sid";
            List<SqlParameter> para_list = new List<SqlParameter>();
            para_list.Add(new SqlParameter("@sid", m_std_info.std_id));
            DataTable dt = new DataTable();
            if (db_op.ExecuteDataTable(sql, para_list, false, ref dt) < 0)
            {
                MessageBox.Show("获取标准失败");
                db_op.CloseDB();
                return -1;
            }
            db_op.CloseDB();

            int res = 0;
            m_std_info.tab_count = dt.Rows.Count;
            m_std_info.std_name = dt.Rows[0]["s_name"].ToString();
            try
            {
                m_std_info.insert_uid = int.Parse(dt.Rows[0]["s_insert_uid"].ToString());
                m_std_info.update_uid = int.Parse(dt.Rows[0]["s_update_uid"].ToString());
                m_std_info.insert_date = DateTime.Parse(dt.Rows[0]["s_insert_date"].ToString());
                m_std_info.update_date = DateTime.Parse(dt.Rows[0]["s_update_date"].ToString());
                m_std_info.relate_flag = (int.Parse(dt.Rows[0]["s_relate_flag"].ToString()) == 1) ? true : false;
                m_std_info.relate_flag = (int.Parse(dt.Rows[0]["s_common_flag"].ToString()) == 1) ? true : false;
            }
            catch (Exception ex)
            {
                Logger.WriteLog(ex.Message);
                return -1;
            }
            for (int i = 0; i < m_std_info.tab_count; i++)
            {
                if (load_tabinfo(dt, i) < 0)
                {
                    res = -1;
                    break;
                }
            }
            return res;
        }

        private int load_tabinfo(DataTable dt, int index)
        {
            int res = 0;
            TabInfo tabinfo = new TabInfo();
            try
            {
                tabinfo.tab_no = int.Parse(dt.Rows[index]["s_tab_no"].ToString());
            }
            catch (Exception ex)
            {
                Logger.WriteLog(ex.Message);
                return -1;
            }
            tabinfo.tab_name = dt.Rows[index]["s_tab_name"].ToString();
            tabinfo.tab_type = dt.Rows[index]["s_tab_type"].ToString();

            switch (tabinfo.tab_type)
            {
                case "RADIO":
                    {
                        for (int i = 0; i < 5; i++)
                        {
                            string value = dt.Rows[index]["s_value_" + (i + 1)].ToString();
                            if (value != null && value != "")
                            {
                                tabinfo.tab_values.Add(value);
                            }
                        }
                    }
                    break;
                case "TARGET":
                    {
                        string value = dt.Rows[index]["s_value_1"].ToString();
                        if (value != null && value != "")
                        {
                            tabinfo.tab_values.Add(value);
                        }
                    }
                    break;
                case "PROGRESS":
                    break;
                default:
                    break;
            }
            m_std_info.tabinfo.Add(tabinfo);
            return res;
        }

        private void init_add_standard()
        {
            comboBoxEx1.Items.Clear();
            for (int i = 1; i <= 10; i++)
            {
                comboBoxEx1.Items.Add(i);
            }
            buttonX7.Enabled = false;
            groupPanel1.Enabled = false;
        }

        private void init_modify_standard()
        {
            //load data from database to memory
            if (load_standard() < 0)
            {
                MessageBox.Show("加载标准失败");
                return;
            }
            radioButton1.Enabled = false;
            radioButton2.Enabled = false;
            radioButton3.Enabled = false;
            radioButton4.Enabled = false;
            radioButton5.Enabled = false;
            buttonX1.Enabled = false;
            buttonX7.Enabled = true;
            groupPanel1.Enabled = true;
            textBoxX1.Text = m_std_info.std_name;
            comboBoxEx1.Items.Clear();
            for (int i = 1; i <= 10; i++)
            {
                comboBoxEx1.Items.Add(i);
            }
            comboBoxEx1.Text = m_std_info.tab_count.ToString();
            comboBoxEx1.Enabled = false;
            if (m_std_info.tabinfo.Count > 0) {
                show_tab_info(0);
                m_std_info.cur_tab_idx = 0;
            }
        }

        private void show_tab_info(int index)
        {
            groupPanel1.Text = "编辑第[" + (index + 1) + "]个标签";
            if (index > m_std_info.tabinfo.Count - 1) {
                Common.CommonDefine.clear_values(panelEx2);
                Common.CommonDefine.clear_values(panelEx3);
                Common.CommonDefine.clear_values(panelEx4);
                return;
            }
            if (index >= 0)
            {
                TabInfo tabinfo = m_std_info.tabinfo[index];
                if (tabinfo.tab_type == "RADIO")
                {
                    m_tab_type = TabTypes.RADIO;
                    radioButton3.Select();
                    textBoxX2.Text = tabinfo.tab_name;
                    for (int i = 0; i < tabinfo.tab_values.Count; i++)
                    {
                        if (i == 0)
                        {
                            textBoxX3.Text = tabinfo.tab_values[i];
                        }
                        else if (i == 1)
                        {
                            textBoxX4.Text = tabinfo.tab_values[i];
                        }
                        else if (i == 2)
                        {
                            textBoxX5.Text = tabinfo.tab_values[i];
                        }
                        else if (i == 3)
                        {
                            textBoxX6.Text = tabinfo.tab_values[i];
                        }
                        else if (i == 4)
                        {
                            textBoxX7.Text = tabinfo.tab_values[i];
                        }
                    }
                }
                else if (tabinfo.tab_type == "TARGET")
                {
                    m_tab_type = TabTypes.TARGET;
                    radioButton4.Select();
                    textBoxX8.Text = tabinfo.tab_name;
                    if (tabinfo.tab_values.Count > 0)
                        textBoxX9.Text = tabinfo.tab_values[0];
                }
                else if (tabinfo.tab_type == "PROGRESS")
                {
                    m_tab_type = TabTypes.PROGRESS;
                    radioButton5.Select();
                    textBoxX10.Text = tabinfo.tab_name;
                }
                else
                {
                    m_tab_type = TabTypes.UNKNOW;
                    MessageBox.Show("无此标签类型 请重新制定标准");
                }

            }
            else
            {
                MessageBox.Show("没有该标签 请重新制定标准");
            }
        }

        private int save_tab(TabInfo tabinfo)
        {
            DBOperator db_op = new DBOperator();
            if (db_op.ConnectDB() < 0)
            {
                MessageBox.Show("无法连接服务器，请检查网络连接");
                return -1;
            }
            int value_count = tabinfo.tab_values.Count;
            string sql = "";
            if (value_count == 0)
            {
                sql = "update standard set s_tab_name=@tab_name, s_tab_type=@tab_type, s_update_uid=@update_uid, s_update_date=@update_date " +
                "where sid = @standard_id and s_tab_no = @tab_id";
            }
            else if (value_count == 1)
            {
                sql = "update standard set s_tab_name=@tab_name, s_tab_type=@tab_type, s_value_1=@value1, s_update_uid=@update_uid, s_update_date=@update_date " +
                "where sid = @standard_id and s_tab_no = @tab_id";
            }
            else if (value_count == 2)
            {
                sql = "update standard set s_tab_name=@tab_name, s_tab_type=@tab_type, s_value_1=@value1, s_value_2=@value2, s_update_uid=@update_uid, s_update_date=@update_date " +
                "where sid = @standard_id and s_tab_no = @tab_id";
            }
            else if (value_count == 3)
            {
                sql = "update standard set s_tab_name=@tab_name, s_tab_type=@tab_type, s_value_1=@value1, s_value_2=@value2, s_value_3=@value3, s_update_uid=@update_uid, s_update_date=@update_date " +
                "where sid = @standard_id and s_tab_no = @tab_id";
            }
            else if (value_count == 4)
            {
                sql = "update standard set s_tab_name=@tab_name, s_tab_type=@tab_type, s_value_1=@value1, s_value_2=@value2, s_value_3=@value3, s_value_4=@value4, s_update_uid=@update_uid, s_update_date=@update_date " +
                "where sid = @standard_id and s_tab_no = @tab_id";
            }
            else if (value_count == 5)
            {
                sql = "update standard set s_tab_name=@tab_name, s_tab_type=@tab_type, s_value_1=@value1, s_value_2=@value2, s_value_3=@value3, s_value_4=@value4, s_value_5=@value5, s_update_uid=@update_uid, s_update_date=@update_date " +
                "where sid = @standard_id and s_tab_no = @tab_id";
            }
            else
            {
                Logger.WriteLog("why values_count is" + value_count.ToString());
                return -1;
            }

            List<SqlParameter> para_list = new List<SqlParameter>();
            int res = 0;
            para_list.Add(new SqlParameter("@standard_id", m_std_info.std_id));
            para_list.Add(new SqlParameter("@tab_id", tabinfo.tab_no));
            para_list.Add(new SqlParameter("@tab_name", tabinfo.tab_name));
            para_list.Add(new SqlParameter("@tab_type", tabinfo.tab_type));
            para_list.Add(new SqlParameter("@update_uid", m_std_info.update_uid));
            para_list.Add(new SqlParameter("@update_date", m_std_info.update_date));
            for (int i = 0; i < value_count; i++)
            {
                para_list.Add(new SqlParameter("@value" + (i + 1), tabinfo.tab_values[i]));
            }
            res = db_op.ExecuteNonQuery(sql, para_list, false);
            para_list.Clear();
            db_op.CloseDB();

            return res;
        }

        private void StandardUi_Load(object sender, EventArgs e)
        {
            radioButton3.Select();
            if (m_modify_mode)
            {
                init_modify_standard();
            }
            else
            {
                init_add_standard();
            }
            if (CurrentUser.user_auth != Authority.ADMIN && CurrentUser.user_auth != Authority.BOSS)
            {
                radioButton1.Select();
                radioButton2.Enabled = false;
            }
            else
            {
                radioButton2.Enabled = true;
            }
        }

        /// <summary>
        /// 生成标签
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void buttonX1_Click(object sender, EventArgs e)
        {
            try
            {
                m_std_info.tab_count = int.Parse(comboBoxEx1.Text);
                comboBoxEx1.Enabled = false;
                buttonX1.Enabled = false;
                groupPanel1.Enabled = true;
                buttonX2.Enabled = false;
            }
            catch (Exception ex)
            {
                Logger.WriteLog(ex.Message);
                MessageBox.Show("请选择标签数量");
            }
        }

        /// <summary>
        /// 业务标准
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void radioButton1_CheckedChanged(object sender, EventArgs e)
        {
            m_std_info.common_flag = false;
        }

        /// <summary>
        /// 常规标准
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void radioButton2_CheckedChanged(object sender, EventArgs e)
        {
            m_std_info.common_flag = true;
        }

        /// <summary>
        /// 单选项
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void radioButton3_CheckedChanged(object sender, EventArgs e)
        {
            Common.CommonDefine.clear_values(panelEx2);
            panelEx2.Visible = true;
            panelEx3.Visible = false;
            panelEx4.Visible = false;
            m_tab_type = TabTypes.RADIO;
        }

        /// <summary>
        /// 目标进度
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void radioButton4_CheckedChanged(object sender, EventArgs e)
        {
            Common.CommonDefine.clear_values(panelEx3);
            panelEx2.Visible = false;
            panelEx3.Visible = true;
            panelEx4.Visible = false;
            m_tab_type = TabTypes.TARGET;
        }

        /// <summary>
        /// 拖动条
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void radioButton5_CheckedChanged(object sender, EventArgs e)
        {
            Common.CommonDefine.clear_values(panelEx4);
            panelEx2.Visible = false;
            panelEx3.Visible = false;
            panelEx4.Visible = true;
            m_tab_type = TabTypes.PROGRESS;
        }

        /// <summary>
        /// 上一个标签
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void buttonX2_Click(object sender, EventArgs e)
        {
            m_std_info.cur_tab_idx = m_std_info.cur_tab_idx - 1;
            if (m_std_info.cur_tab_idx == 0)
                buttonX2.Enabled = false;
            buttonX4.Enabled = true;
            show_tab_info(m_std_info.cur_tab_idx);
        }

        /// <summary>
        /// 保存标签
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void buttonX3_Click(object sender, EventArgs e)
        {
            bool modify_tab = false;
            if (m_std_info.cur_tab_idx <= m_std_info.tabinfo.Count - 1)
                modify_tab = true;

            TabInfo tabinfo = new TabInfo();
            switch (m_tab_type)
            {
                case TabTypes.RADIO:
                    {
                        if (textBoxX2.Text == "")
                        {
                            MessageBox.Show("请输入标签名");
                            return;
                        }
                        tabinfo.tab_name = textBoxX2.Text;
                        tabinfo.tab_type = "RADIO";
                        tabinfo.tab_no = m_std_info.cur_tab_idx + 1;
                        tabinfo.tab_values.Clear();
                        if (textBoxX3.Text != "")
                            tabinfo.tab_values.Add(textBoxX3.Text);
                        if (textBoxX4.Text != "")
                            tabinfo.tab_values.Add(textBoxX4.Text);
                        if (textBoxX5.Text != "")
                            tabinfo.tab_values.Add(textBoxX5.Text);
                        if (textBoxX6.Text != "")
                            tabinfo.tab_values.Add(textBoxX3.Text);
                        if (textBoxX7.Text != "")
                            tabinfo.tab_values.Add(textBoxX3.Text);

                        if (!modify_tab)
                        {
                            m_std_info.tabinfo.Add(tabinfo);
                        }
                        else
                        {
                            m_std_info.tabinfo.RemoveAt(m_std_info.cur_tab_idx);
                            m_std_info.tabinfo.Insert(m_std_info.cur_tab_idx, tabinfo);
                        }
                        MessageBox.Show("保存标签成功");
                    }
                    break;
                case TabTypes.TARGET:
                    {
                        if (textBoxX8.Text == "")
                        {
                            MessageBox.Show("请输入标签名");
                            return;
                        }
                        tabinfo.tab_name = textBoxX8.Text;
                        tabinfo.tab_type = "TARGET";
                        tabinfo.tab_no = m_std_info.cur_tab_idx + 1;
                        tabinfo.tab_values.Clear();
                        if (textBoxX9.Text != "")
                            tabinfo.tab_values.Add(textBoxX9.Text);

                        if (!modify_tab)
                        {
                            m_std_info.tabinfo.Add(tabinfo);
                        }
                        else
                        {
                            m_std_info.tabinfo.RemoveAt(m_std_info.cur_tab_idx);
                            m_std_info.tabinfo.Insert(m_std_info.cur_tab_idx, tabinfo);
                        }
                        MessageBox.Show("保存标签成功");
                    }
                    break;
                case TabTypes.PROGRESS:
                    {
                        if (textBoxX10.Text == "")
                        {
                            MessageBox.Show("请输入标签名");
                            return;
                        }
                        tabinfo.tab_name = textBoxX10.Text;
                        tabinfo.tab_type = "PROGRESS";
                        tabinfo.tab_no = m_std_info.cur_tab_idx + 1;
                        if (!modify_tab)
                        {
                            m_std_info.tabinfo.Add(tabinfo);
                        }
                        else
                        {
                            m_std_info.tabinfo.RemoveAt(m_std_info.cur_tab_idx);
                            m_std_info.tabinfo.Insert(m_std_info.cur_tab_idx, tabinfo);
                        }
                        MessageBox.Show("保存标签成功");
                    }
                    break;
                default:
                    Logger.WriteLog("why TabTyps is" + m_tab_type.ToString());
                    break;
            }
    
        }

        /// <summary>
        /// 下一个标签
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void buttonX4_Click(object sender, EventArgs e)
        {
            m_std_info.cur_tab_idx = m_std_info.cur_tab_idx + 1;
            if (m_std_info.cur_tab_idx == m_std_info.tab_count - 1)
                buttonX4.Enabled = false;
            buttonX2.Enabled = true;
            show_tab_info(m_std_info.cur_tab_idx);
        }

        /// <summary>
        /// 标准预览
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void buttonX5_Click(object sender, EventArgs e)
        {

        }

        /// <summary>
        /// 制定标准
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void buttonX6_Click(object sender, EventArgs e)
        {
            if (textBoxX1.Text == "")
            {
                MessageBox.Show("请输入标准名称");
                return;
            }
            m_std_info.std_name = textBoxX1.Text;
            int count = m_std_info.tab_count - m_std_info.tabinfo.Count;
            if (count > 0)
            {
                MessageBox.Show("您还有" + count + "个标签没有制作");
                return;
            }

            if (m_modify_mode)
            {
                m_std_info.update_uid = CurrentUser.user_id;
                m_std_info.update_date = DateTime.Now;
            }
            else {
                m_std_info.insert_uid = CurrentUser.user_id;
                m_std_info.insert_date = DateTime.Now;
                m_std_info.update_uid = CurrentUser.user_id;
                m_std_info.update_date = DateTime.Now;
                m_std_info.relate_flag = false;
            }

            DBOperator db_op = null;
            string sql = "";
            DataTable dt = null;
            List<SqlParameter> para_list = null;
            int res = 0;
            if (!m_modify_mode)
            {
                //calculate the new standard_id
                sql = "select sid from standard";
                db_op = new DBOperator();
                if (db_op.ConnectDB() < 0)
                {
                    MessageBox.Show("无法连接服务器，请检查网络连接");
                    return;
                }
                dt = new DataTable();
                if (db_op.ExecuteDataTable(sql, null, false, ref dt) < 0)
                {
                    db_op.CloseDB();
                    return;
                }
                int row_count = dt.Rows.Count;
                if (row_count > 0)
                {
                    int last_std_id = 0;
                    try
                    {
                        last_std_id = int.Parse(dt.Rows[row_count - 1][0].ToString());
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("非法标准ID");
                        Logger.WriteLog(ex.Message);
                        return;
                    }
                    //TODO it may exceed the max value of type int, need to find another way later 
                    m_std_info.std_id = last_std_id + 1;
                }
                else
                {
                    m_std_info.std_id = 10000;
                }

                sql = "insert into standard(sid, s_tab_no, s_name, s_common_flag, s_relate_flag, s_insert_uid, s_insert_date, s_update_uid, s_update_date) " +
                    "values(@standard_id, @tab_id, @standard_name, @common_flag, @relate_flag, @insert_uid, @insert_date, @update_uid, @update_date)";
                para_list = new List<SqlParameter>();
                res = 0;
                for (int i = 0; i < m_std_info.tab_count; i++)
                {
                    para_list.Clear();
                    para_list.Add(new SqlParameter("@standard_id", m_std_info.std_id));
                    para_list.Add(new SqlParameter("@tab_id", m_std_info.tabinfo[i].tab_no));
                    para_list.Add(new SqlParameter("@standard_name", m_std_info.std_name));
                    para_list.Add(new SqlParameter("@common_flag", m_std_info.common_flag ? 0 : 1));
                    para_list.Add(new SqlParameter("@relate_flag", m_std_info.relate_flag ? 1 : 0));
                    para_list.Add(new SqlParameter("@insert_uid", m_std_info.insert_uid));
                    para_list.Add(new SqlParameter("@insert_date", m_std_info.insert_date));
                    para_list.Add(new SqlParameter("@update_uid", m_std_info.update_uid));
                    para_list.Add(new SqlParameter("@update_date", m_std_info.update_date));
                    if ((res = db_op.ExecuteNonQuery(sql, para_list, false)) < 0)
                        break;
                }

                if (res <= 0)
                {
                    Logger.WriteLogError("create standard fail");
                    MessageBox.Show("创建标准失败");
                    db_op.CloseDB();
                    return;
                }
                db_op.CloseDB();
            }

            bool flag = true;
            m_std_info.update_date = DateTime.Now;
            for (int i = 0; i < m_std_info.tabinfo.Count; i++) {
                if (save_tab(m_std_info.tabinfo[i]) < 0) {
                    flag = false;
                    Logger.WriteLogError("save tab_info fail");
                    MessageBox.Show("提交标签失败");
                    break;
                }
            }

            if (!flag && !m_modify_mode)
            {
                if (db_op.ConnectDB() < 0)
                {
                    MessageBox.Show("无法连接服务器，请检查网络连接");
                    return;
                }
                sql = "delete from Standard where sid=@std_id";
                para_list.Clear();
                para_list.Add(new SqlParameter("@std_id", m_std_info.std_id));
                if (db_op.ExecuteNonQuery(sql, para_list, false) < 0)
                {
                    Logger.WriteLogError("delete standard fail");
                    MessageBox.Show("删除标准失败");
                }
                else
                    MessageBox.Show("删除标准成功");
                db_op.CloseDB();
            }
            else {
                Logger.WriteLog("create standard success");
                MessageBox.Show("创建标准成功");
            }
            
            if (OnChange != null)
                OnChange(sender, e);
            this.Close();
        }

        /// <summary>
        /// 删除标准
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void buttonX7_Click(object sender, EventArgs e)
        {
            DBOperator db_op = new DBOperator();
            if (db_op.ConnectDB() < 0)
            {
                MessageBox.Show("无法连接服务器，请检查网络连接");
                return;
            }

            //判断该标准是否有关联者 若有则必须先删除关联才能删除
            DataTable dt = new DataTable();
            List<SqlParameter> para_list = new List<SqlParameter>();
            string sql = "select us_uid from user_standard where us_sid=@std_id";
            para_list.Add(new SqlParameter("@std_id", m_std_info.std_id));
            if (db_op.ExecuteDataTable(sql, para_list, false, ref dt) < 0)
            {
                MessageBox.Show("删除失败");
                db_op.CloseDB();
                return;
            }
            if (dt.Rows.Count > 0)
            {
                //存在关联
                DialogResult dr = MessageBox.Show("当前标准已关联员工，是否删除关联？", "删除关联", MessageBoxButtons.OKCancel);
                if (dr == DialogResult.OK)
                {
                    //删除关联
                    sql = "delete from user_standard where us_sid=@std_id";
                    para_list.Clear();
                    para_list.Add(new SqlParameter("@std_id", m_std_info.std_id));
                    if (db_op.ExecuteNonQuery(sql, para_list, false) < 0)
                    {
                        Logger.WriteLog("delete user_standard fail");
                        MessageBox.Show("删除关联失败");
                        db_op.CloseDB();
                        return;
                    }
                    else
                        MessageBox.Show("删除关联成功");
                }
                else
                {
                    return;
                }
            }

            sql = "delete from Standard where sid=@std_id";
            para_list.Clear();
            para_list.Add(new SqlParameter("@std_id", m_std_info.std_id));
            if (db_op.ExecuteNonQuery(sql, para_list, false) < 0)
            {
                Logger.WriteLog("delete standard fail");
                MessageBox.Show("删除标准失败");
            }
            else
                MessageBox.Show("删除标准成功");
            db_op.CloseDB();
            if (OnChange != null)
                OnChange(sender, e);
            this.Close();
        }

        private StandardInfo m_std_info;
        private TabTypes m_tab_type;
        private bool m_modify_mode;
        public delegate void StandardChange(object sender, EventArgs e);
        public event StandardChange OnChange;
    }

    class StandardInfo
    {
        public StandardInfo()
        {
            std_id = -1;
            std_name = "";
            tab_count = -1;
            relate_flag = false;
            common_flag = false;
            insert_uid = -1;
            update_uid = -1;
            cur_tab_idx = 0;
            tabinfo = new List<TabInfo>();
        }

        public int std_id;
        public string std_name;
        public int tab_count;
        public List<TabInfo> tabinfo;
        public bool relate_flag;
        public bool common_flag;
        public int insert_uid;
        public int update_uid;
        public DateTime insert_date;
        public DateTime update_date;
        public int cur_tab_idx;
    }

    class TabInfo
    {
        public TabInfo()
        {
            tab_no = 0;
            tab_name = "";
            tab_type = "";
            tab_saved = false;
            tab_values = new List<string>();
        }
        public int tab_no;
        public string tab_name;
        public string tab_type;
        public bool tab_saved;
        public List<string> tab_values;
    }
}
